<?php
require_once(APP_OBJ_PATH . 'model.class.php');

/**
 * Product
 *
 * @package scorpion-magenta
 * @author Nicky van Meurs
 * @copyright 2012
 * @version 1.0
 * @access public
 */
class Product extends Model
{
	protected $ProductID;
	protected $Artikelnummer;
	protected $Artikelnaam;
	protected $Kleur;
	protected $Maat;
	protected $Verkoopprijs;
	protected $Omschrijving;
	protected $Afbeelding;
	protected $ProductlijstID;

	public static function getAllByArtikelnaam($artikelnaam)
	{
		global $db;
		$returnData = array ();
		$stmt = $db->prepare(self::getSelect() . " WHERE Artikelnaam = :artikelnaam");
		$stmt->execute(array(':artikelnaam' => $artikelnaam));
		$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
		foreach ($rows as $row)
			$returnData[] = new static($row);
		return $returnData;
	}

	public static function getAllByProductlijstId($productlijstId, $groupBy = false, $orderBy = false, $productID = false)
	{

			$sql = ($groupBy)? "GROUP BY `Artikelnaam`" : "";

			if($orderBy)
			{
				if(empty($productID))
					die("productID is needed.");

				$sql= "AND Artikelnaam IN (SELECT Artikelnaam FROM product WHERE ProductID = :productid)";
			}


			global $db;
			$returnData = array ();
			$stmt = $db->prepare(self::getSelect() . " WHERE ProductlijstID = :productlijstId " . $sql);
			$stmt->bindParam(':productlijstId', $productlijstId);
			if(!empty($productID))
				$stmt->bindParam(':productid', $productID);

			$stmt->execute();
			$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
			foreach ($rows as $row)
				$returnData[] = new static($row);
			return $returnData;
	}


}
?>
